// Decompiled on 周六 2月 22 19:31:49 CST 2025 with Zomboid Decompiler v0.1.3 using Vineflower.
package zombie.scripting;

import java.util.Stack;

public final class ScriptParsingUtils {
    public static String[] SplitExceptInbetween(String src, String delimiter, String exceptionContainerOpen) {
        Stack stack = new Stack();
        boolean _boolean = false;

        while (src.contains(delimiter)) {
            if (!_boolean) {
                int int0 = src.indexOf(delimiter);
                int int1 = src.indexOf(exceptionContainerOpen);
                if (int1 == -1) {
                    String[] string0 = src.split(delimiter);

                    for (int int2 = 0; int2 < string0.length; int2++) {
                        stack.add(string0[int2].trim());
                    }

                    string0 = new String[stack.size()];

                    for (int int3 = 0; int3 < stack.size(); int3++) {
                        string0[int3] = (String)stack.get(int3);
                    }

                    return string0;
                }

                if (int0 == -1) {
                    String[] string1 = new String[stack.size()];
                    if (!src.trim().isEmpty()) {
                        stack.add(src.trim());
                    }

                    for (int int4 = 0; int4 < stack.size(); int4++) {
                        string1[int4] = (String)stack.get(int4);
                    }

                    return string1;
                }

                if (int0 < int1) {
                    stack.add(src.substring(0, int0));
                    src = src.substring(int0 + 1);
                } else {
                    _boolean = true;
                }
            } else {
                int int5 = src.indexOf(exceptionContainerOpen);
                int int6 = src.indexOf(exceptionContainerOpen);
                int int7 = src.indexOf(exceptionContainerOpen, src.indexOf(exceptionContainerOpen) + 1);
                int int8 = src.indexOf(delimiter, int7 + 1);
                if (int8 == -1) {
                    break;
                }

                String string2 = src.substring(0, int8).trim();
                if (!string2.isEmpty()) {
                    stack.add(string2);
                }

                src = src.substring(int8 + 1);
                _boolean = false;
            }
        }

        if (!src.trim().isEmpty()) {
            stack.add(src.trim());
        }

        String[] string3 = new String[stack.size()];

        for (int int9 = 0; int9 < stack.size(); int9++) {
            string3[int9] = (String)stack.get(int9);
        }

        return string3;
    }

    public static String[] SplitExceptInbetween(String src, String delimiter, String exceptionContainerOpen, String exceptionContainerCloser) {
        int int0 = 0;
        int int1 = 0;
        int int2 = 0;
        int int3 = 0;
        int3 = 0;
        int0 = 0;
        int1 = 0;
        int2 = 0;
        Stack stack = new Stack();
        if (src.indexOf(exceptionContainerOpen, int0) == -1) {
            return src.split(delimiter);
        } else {
            do {
                int0 = src.indexOf(exceptionContainerOpen, int0 + 1);
                int1 = src.indexOf(exceptionContainerCloser, int1 + 1);
                int2 = src.indexOf(delimiter, int2 + 1);
                if (int2 == -1) {
                    stack.add(src.trim());
                    src = "";
                } else if ((int2 < int0 || int0 == -1 && int2 != -1) && int3 == 0) {
                    stack.add(src.substring(0, int2));
                    src = src.substring(int2 + 1);
                    int0 = 0;
                    int1 = 0;
                    int2 = 0;
                } else if ((int1 >= int0 || int1 == -1) && int0 != -1) {
                    if (int0 != -1 && int1 == -1) {
                        int1 = int0;
                        int3++;
                    } else if (int0 != -1 && int1 != -1 && int0 < int1 && (int0 > int2 || int1 < int2)) {
                        stack.add(src.substring(0, int2));
                        src = src.substring(int2 + 1);
                        int0 = 0;
                        int1 = 0;
                        int2 = 0;
                    }
                } else {
                    int0 = int1;
                    if (--int3 == 0) {
                        stack.add(src.substring(0, int1 + 1));
                        src = src.substring(int1 + 1);
                        int0 = 0;
                        int1 = 0;
                        int2 = 0;
                    }
                }
            } while (src.trim().length() > 0);

            if (!src.trim().isEmpty()) {
                stack.add(src.trim());
            }

            String[] string = new String[stack.size()];

            for (int int4 = 0; int4 < stack.size(); int4++) {
                string[int4] = ((String)stack.get(int4)).trim();
            }

            return string;
        }
    }
}
